#     Xepec.ru - социальная сеть
#     Copyright (C) 2008  Fedorchenko Alexander <admin@xepec.ru>
#
#     This program is free software: you can redistribute it and/or modify
#     it under the terms of the GNU Affero General Public License as
#     published by the Free Software Foundation, either version 3 of the
#     License, or (at your option) any later version.
#
#     This program is distributed in the hope that it will be useful,
#     but WITHOUT ANY WARRANTY; without even the implied warranty of
#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#     GNU Affero General Public License for more details.
#
#     You should have received a copy of the GNU Affero General Public License
#     along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#     Autor: Fedorchenko Alexander
#     Mail: <admin@xepec.ru>
#     Date: 06/02/2010
#

require "../core.pl";
#require "../config.pl";

require "lib_search.pl";


&get_query();

$auth_id = do_check();
my $act = $queryString{"act"};
my $cat = $queryString{"cat"};
#$act = "search-new";

##################################################################
##################-Правельный вариант-############################
##################################################################
$uname_get=$queryString{ "uname" };                   ########
if (defined($uname_get))                                ####
{                                                       ####
	if ($uname_get != $auth_id)                     ####
	{                                               ####
		$masha=0;                               ####
	}                                               ####
	else                                            ####
	{                                               ####
		$masha=1;                               ####
	}                                               ####
	$uname_id=$uname_get;                           ####
}                                                       ####
else                                                    ####
{                                                       ####
        $masha=1;                                       ####
#	print "Location: ?uname=$auth_id\n\n";          ####
#	exit();                                         ####
	$uname_id=$auth_id;                             ####
}                                                       ####
@uname = uname_get($uname_id);                        ########
#################################################################
#################################################################
#################################################################
#используется в /litera/index.pl, /musik/index.php||pl, /groups/index.pl, search/index.pl

#print $masha."\n\n\n\n\n";
#if(!$auth_id) {print "Location: http://xepec.ru\n\n"; exit();};
if(!$act) {$act="search-new";}

###############################################################################################################################
#----------------------------------------------Вывод на экран информации------------------------------------------------------#
###############################################################################################################################

print "Content-type: text/xml; charset=utf-8\n\n";
print qq{<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="./search.xsl"?>
<document>
    <user id="@uname['0']" nic="@uname['3']" />
    <site_name>$SITE_NAME</site_name>
    <site_name2>$SITE_NAME2</site_name2>
    <title>$SITE_NAME :: Поиск друзей</title>
    <version>v 0.2</version>
    };
if ($auth_id)
	{	
		print qq{
	<message>TRUE</message>};
	}
	
do_print_menu();


use Switch;
switch ($act)
{
	case "menu"
	{
		print qq{
		<content>
			<data>
			<menu>
				<item name="$cat" />
			</menu>
			</data>
		</content>
		};
	}
	case "search"
	{	
		#$search_query = $querySting{"s"};
		#use Switch;
		#switch ($act){case "username"{}case "groups"{}case "litera"{}case "video"{}case ""}
		print qq{
		<content>
			<data>
			<menu>
				<item name="$cat" />
			</menu>
			<search>};
				use CGI;
				my $cgi = new CGI;
				my $name = $cgi->param('name');
				
				#$phone = "+ ".$cgi->param('phone_country')." (".$cgi->param('phone_city').") ".$cgi->param('phone_number');
				
				my %search_param;
				$search_param{"email"} = $cgi->param('email');
				$search_param{"nic"} = $cgi->param('nic');
				$search_param{"name"} = $cgi->param('name');
				$search_param{"sex"} = $cgi->param('sex');
				#%search_param{"bdate"} = $cgi->param('name');
				$search_param{"phone_country"} = $cgi->param('phone_country'); $search_param{"phone_city"} = $cgi->param('phone_city'); $search_param{"phone_number"} =$cgi->param('phone_number');
				#$search_param{"phone"} = $phone;
				$search_param{"foto"} = $cgi->param('foto');
				#$search_param{"name1"} = $cgi->param('name');
				#$search_param{"name"} = $cgi->param('name');
				
				
				search_username(%search_param);
				
	#  			sub f {
	# 			
	#  			     my $a={@_}->{'foto'};
	#  			     print $a;
	#  			 }
	#  			 f(%search_param);
	 
	print qq{\n\t\t</search>
			</data>
		</content>};
	}
	case "search-new"
	{
		print qq{
		<content>
			<data>
			
			<search-new>};
				use CGI;
				my $cgi = new CGI;
				my $name = $cgi->param('name');
				
				#$phone = "+ ".$cgi->param('phone_country')." (".$cgi->param('phone_city').") ".$cgi->param('phone_number');
				
				my %search_param;
				$search_param{"email"} = $cgi->param('email');
				$search_param{"nic"} = $cgi->param('nic');
				$search_param{"name"} = $cgi->param('name');
				$search_param{"sex"} = $cgi->param('sex');
				#%search_param{"bdate"} = $cgi->param('name');
				$search_param{"phone_country"} = $cgi->param('phone_country'); $search_param{"phone_city"} = $cgi->param('phone_city'); $search_param{"phone_number"} =$cgi->param('phone_number');
				#$search_param{"phone"} = $phone;
				$search_param{"foto"} = $cgi->param('foto');
				#$search_param{"name1"} = $cgi->param('name');
				#$search_param{"name"} = $cgi->param('name');
				
				
				search_username(%search_param);
				
	#  			sub f {
	# 			
	#  			     my $a={@_}->{'foto'};
	#  			     print $a;
	#  			 }
	#  			 f(%search_param);
	 	print qq{\n\t\t</search-new>
			</data>
		</content>};
	}
}
print qq{
</document>};
